﻿#include "StringOperation.h"
#ifdef QT_VERSION
const vector<QString> StringOperation::strtok(const QString& Text, const QString& Delimiter)
{
    vector<QString> ret;
    if (Text.isEmpty() || Delimiter.isEmpty())
        return ret;
    int len = strlen(Text.toUtf8().data());
    char* buf = new char[len + 1] {0};
    ::strcpy(buf, Text.toUtf8().data());
    for (char* p = ::strtok(buf, Delimiter.toLocal8Bit().data()); p != NULL; p = ::strtok(NULL, Delimiter.toLocal8Bit().data()))
    {
        ret.push_back(p);
    }
    delete[] buf;
    return ret;
}
#endif
const vector<string> StringOperation::strtok(const string& Text, const string& Delimiter)
{
    vector<string> ret;
    if (Text.empty() || Delimiter.empty())
        return ret;
    char* buf = new char[Text.size() + 1] {0};
    ::strcpy(buf, Text.c_str());
    for (char* p = ::strtok(buf, Delimiter.c_str()); p != NULL; p = ::strtok(NULL, Delimiter.c_str()))
    {
        ret.push_back(p);
    }
    delete[] buf;
    return ret;
}
